﻿<cfsilent>
	<cfscript>
		
		usageAdvice = getProperty("serviceFactory").getBean("classroomTypeUsageAdvice");

		event.setArg("pageTitle", "教学运行基础数据 - 教学场地类别");
		
		currentTab = event.getArg("TabID","labFixed");
		
		sql = "SELECT
					ct.cr_type,ct.cr_type_name,
					(SELECT COUNT(c.cr_id) FROM t_classroom c WHERE c.cr_type = ct.cr_type) c_count,
					ct.cr_usage
				FROM
					t_classroom_type ct
				WHERE
					ct.cr_type LIKE '0__'
				ORDER BY
					ct.cr_type";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_fixType = queryObj.execute( sql = sql ).getResult();

		sql = "	SELECT
					ct.cr_type,ct.cr_type_name,
					(SELECT COUNT(c.cr_id) FROM t_classroom c WHERE c.cr_type = ct.cr_type) c_count,
					ct.cr_usage,
					ct.spec_deps
				FROM
					t_classroom_type ct
				WHERE
					ct.cr_type LIKE 'Z__'
				ORDER BY
					ct.cr_type";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_customizeType = queryObj.execute( sql = sql ).getResult();
		

		sql = "SELECT
					i.institute_id,i.institute_short
				FROM
					t_institute i
				WHERE
					i.classification = '1'
				ORDER BY
					i.institute_short";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_institute = queryObj.execute( sql = sql ).getResult();
		
		sql = "SELECT
					i.institute_id,i.institute_short
				FROM
					t_institute i
				WHERE
					i.classification = '3'
				ORDER BY
					i.institute_short";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_department = queryObj.execute( sql = sql ).getResult();
		
		
		passArgs = structNew();
		
		typeId = event.getArg("TYPE");
		
		rs_typeEntity = queryNew("cr_type");
		
		if ( len(typeId) ) {
			
			sql = "	SELECT
						ct.cr_type,ct.cr_type_name,ct.spec_deps
					FROM
						t_classroom_type ct
					WHERE
						ct.cr_type = :typeId ";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "typeId", value = typeId, cfsqltype = "cf_sql_char");
			rs_typeEntity = queryObj.execute( sql = sql ).getResult();
			
			currentTab = event.getArg("TabID", "labModify");

		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('classroomResource')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学场地维护</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教学场地类别维护
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labFixed">class="active"</cfif> id="labFixed" tabTarget="Fixed">默认类别</span>
						<span <cfif currentTab eq "labCustomized">class="active"</cfif> id="labCustomized" tabTarget="Customized">自定义类别</span>
						<cfif rs_typeEntity.recordCount GT 0>
							<span <cfif currentTab eq "labModify">class="active"</cfif> id="labModify" tabTarget="Modify">修改类别设置</span>
							<cfelse>
							<span <cfif currentTab eq "labSetup">class="active"</cfif> id="labSetup" tabTarget="Setup">添加类别</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});


						/* classroomType usage trigger */
						$("a[usage]").click(function(){
							

							var rowid = $(this).attr("rowid");
							var method = $(this).attr("usage");

							var status = $(this).hasClass("yes");

							var newStatus = true;

							var $row = $("tr.editRows[rowid='" + rowid + "']");

							/* 切换状态数据 */
							if (status) {
								newStatus = false;
							}

							/* 发送请求 */
							$(this).removeClass("no").removeClass("yes").addClass("waiting");

							$.post(
									"<cfoutput>#buildURL('apiClassroomTypeUsageChange')#</cfoutput>", 
									{
										'typeid' : rowid,
										'prop' : method,
										'status' : newStatus,
										'seed': (new Date()).getTime()
									}, 
									function(data) {
											
										result = $.parseJSON(data);

										$(this).removeClass("waiting");

										/* 刷新教室状态数据 */
										if (result.Running) { $("a[usage='Running']", $row).removeClass("no").addClass("yes"); } else { $("a[usage='Running']", $row).removeClass("yes").addClass("no"); }

										if (result.ForCourse) { $("a[usage='ForCourse']", $row).removeClass("no").addClass("yes"); } else { $("a[usage='ForCourse']", $row).removeClass("yes").addClass("no"); }
										if (result.ForExam) { $("a[usage='ForExam']", $row).removeClass("no").addClass("yes"); } else { $("a[usage='ForExam']", $row).removeClass("yes").addClass("no"); }
										if (result.ForBorrow) { $("a[usage='ForBorrow']", $row).removeClass("no").addClass("yes"); } else { $("a[usage='ForBorrow']", $row).removeClass("yes").addClass("no"); }
											
									});
										
							});
					
					});
					// -->
					//]]>				
				</script>

				<div id="Fixed" class="tabContent">
					
					<div class="noticeBlock">
						<h3>固定类别</h3>
						<hr/>
					</div>
					
					<cfif rs_fixType.recordCount>
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>教学场地类别</td>
									<td width="80">教室数</td>
									<td width="50">状态</td>
									<td width="50">排课</td>
									<td width="50">考试</td>
									<td width="50">借用</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_fixType">

									<cfset usageAdvice.parseUsage( rs_fixType.cr_usage ) />
									
									<tr class="editRows" rowid="<cfoutput>#rs_fixType.cr_type#</cfoutput>">
										<td><span class="index"><cfoutput>#rs_fixType.cr_type#</cfoutput></span></td>
										<td><cfoutput>#rs_fixType.cr_type_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_fixType.c_count#</cfoutput></span></td>
										<td><a rowid="<cfoutput>#rs_fixType.cr_type#</cfoutput>" usage="Running" href="javascript:void(0);" class="stat <cfif usageAdvice.getRunning()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_fixType.cr_type#</cfoutput>" usage="ForCourse" href="javascript:void(0);" class="stat <cfif usageAdvice.getForCourse()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_fixType.cr_type#</cfoutput>" usage="ForExam" href="javascript:void(0);" class="stat <cfif usageAdvice.getForExam()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_fixType.cr_type#</cfoutput>" usage="ForBorrow" href="javascript:void(0);" class="stat <cfif usageAdvice.getForBorrow()>yes<cfelse>no</cfif>"></a></td>
									</tr>
									
								</cfloop>
							</tbody>
						</table>
						
						<cfset structDelete( passArgs, "TYPE" ) />

					</cfif>
					
				</div>
				
				<div id="Customized" class="tabContent">
					
					<div class="noticeBlock">
						<h3>自定义类别</h3>
						<hr/>
					</div>
					
					<cfif rs_customizeType.recordCount>
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>教学场地类别</td>
									<td>可用院系</td>
									<td width="80">教室数</td>
									<td width="50">状态</td>
									<td width="50">排课</td>
									<td width="50">考试</td>
									<td width="50">借用</td>
									<td width="16"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_customizeType">
									<cfset usageAdvice.parseUsage( rs_customizeType.cr_usage ) />
									<cfset structInsert( passArgs, "TYPE", rs_customizeType.cr_type, true ) />
									
									<tr class="editRows" rowid="<cfoutput>#rs_customizeType.cr_type#</cfoutput>">
										<td><span class="index"><cfoutput>#rs_customizeType.cr_type#</cfoutput></span></td>
										<td><cfoutput>#rs_customizeType.cr_type_name#</cfoutput></td>
										<td>
											<cfif rs_customizeType.spec_deps eq "ALL">
												全部
												<cfelse>
													
                                                    <cfset sql = "SELECT
																		i.institute_short
																	FROM
																		t_institute i
																	WHERE
																		i.institute_id IN (:depIds )"/>
													<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                                                    <cfset queryObj.addParam(name = "depIds", value = rs_customizeType.spec_deps, cfsqltype = "cf_sql_varchar", list = true) />
                                                    <cfset rs_dep = queryObj.execute(sql = sql).getResult() />
													<cfoutput>#valueList( rs_dep.institute_short, ", " )#</cfoutput>
											</cfif>
										</td>
										<td><span class="numeric"><cfoutput>#rs_customizeType.c_count#</cfoutput></span></td>
										<td><a rowid="<cfoutput>#rs_customizeType.cr_type#</cfoutput>" usage="Running" href="javascript:void(0);" class="stat <cfif usageAdvice.getRunning()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_customizeType.cr_type#</cfoutput>" usage="ForCourse" href="javascript:void(0);" class="stat <cfif usageAdvice.getForCourse()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_customizeType.cr_type#</cfoutput>" usage="ForExam" href="javascript:void(0);" class="stat <cfif usageAdvice.getForExam()>yes<cfelse>no</cfif>"></a></td>
										<td><a rowid="<cfoutput>#rs_customizeType.cr_type#</cfoutput>" usage="ForBorrow" href="javascript:void(0);" class="stat <cfif usageAdvice.getForBorrow()>yes<cfelse>no</cfif>"></a></td>
										<td><a href="<cfoutput>#buildURL('classroomType', passArgs)#</cfoutput>" class="stat edit"></a></td>
									</tr>
									
								</cfloop>
							</tbody>
						</table>
						
						<cfset structDelete( passArgs, "TYPE" ) />

					</cfif>

				</div>
				
				<cfif rs_typeEntity.recordCount eq 0>

					<div id="Setup" class="tabContent">
					
						<div class="noticeBlock">
							<h3>添加教室类别</h3>
							<hr/>
						</div>
						
						<form id="formCreate" onSubmit="javascript:return processVerfiyForm('formCreate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('classroomTypeCreateDo')#</cfoutput>">
							
							<input type="hidden" name="TabID" value="labCustomized" />
							
							<div class="label">
								<b>类别</b>
								<input name="TypeName" id="TypeName" verification="required" type="text" class="typeText" maxlength="14" value="<cfoutput>#event.getArg( 'TypeName' )#</cfoutput>" />
							</div>
							
							<div class="label">
								<b>适用学院</b>
								
								<input name="FullInstitute" id="FullInstitute" type="checkbox" class="typeCheckbox" value="1" checked="checked" /> 全部
								
								<div id="notFullInstitute" class="secondRow hidden_elem mtm">
									任课学院
									<table>
										<tr>
											<cfset row = 0 />
											<cfset cellPerRow = 6 />
                                            <cfloop query="rs_institute">
												<cfset row++ />
													<td>
														<input name="targetInstitute" type="checkbox" class="typeCheckbox" <cfif row eq 1>verification="group"</cfif> value="<cfoutput>#rs_institute.institute_id#</cfoutput>" checked="checked" />
														<cfoutput>#rs_institute.institute_short#</cfoutput>
													</td>
												<cfif row mod cellPerRow eq 0>
										</tr>
										<tr>
												</cfif>
											</cfloop>
											<cfif row eq rs_institute.recordCount and rs_institute.recordCount mod cellPerRow>
												<cfloop from="1" to="#cellPerRow-rs_institute.recordCount mod cellPerRow#" index="i">
													<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
												</cfloop>
											</cfif>
										</tr>
									</table>
								
									教辅部门
									<table>
										<tr>
											<cfset row = 0 />
											<cfset cellPerRow = 6 />
                                            <cfloop query="rs_department">
												<cfset row++ />
													<td>
														<input name="targetInstitute" type="checkbox" class="typeCheckbox" value="<cfoutput>#rs_department.institute_id#</cfoutput>" checked="checked" />
														<cfoutput>#rs_department.institute_short#</cfoutput>
													</td>
												<cfif row mod cellPerRow eq 0>
										</tr>
										<tr>
												</cfif>
											</cfloop>
											<cfif row eq rs_department.recordCount and rs_department.recordCount mod cellPerRow>
												<cfloop from="1" to="#cellPerRow-rs_department.recordCount mod cellPerRow#" index="i">
													<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
												</cfloop>
											</cfif>
										</tr>
									</table>
								</div>

							</div>
							
							<div class="lable">
								<input class="button" type="submit" value="添加" />
							</div>
							
						</form>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$(document).ready(function() {
								
								$("#FullInstitute").change(function(){
								
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#notFullInstitute").addClass("hidden_elem");
										$("#notFullInstitute :checkbox[name='targetInstitute']").attr("checked","checked");
									}
									else {
										$("#notFullInstitute").removeClass("hidden_elem");
										$("#notFullInstitute :checkbox[name='targetInstitute']").removeAttr("checked");
									}
								});

							});
							// -->
							//]]>
						</script>
						
					</div>
					
				</cfif>
				
				<cfif rs_typeEntity.recordCount GT 0>
					
					<cfset structInsert( passArgs, "TYPE", rs_typeEntity.cr_type, true ) />
					
					<div id="Modify" class="tabContent">
						
						<div class="noticeBlock">
							<h3>修改教室类别</h3>
							<hr/>
						</div>
						
						<form id="formUpdate" onSubmit="javascript:return processVerfiyForm('formUpdate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('classroomTypeUpdateDo')#</cfoutput>">
							
							<input type="hidden" name="TabID" value="labCustomized" />
							<input type="hidden" name="Type" value="<cfoutput>#rs_typeEntity.cr_type#</cfoutput>" />
							
							<div class="label">
								<b>类别</b>
								<input name="TypeName" id="TypeName" verification="required" type="text" class="typeText" maxlength="14" value="<cfoutput>#event.getArg( 'TypeName', rs_typeEntity.cr_type_name )#</cfoutput>" />
							</div>
							
							<div class="label">
								<b>适用学院</b>
								
								<input name="FullInstitute" id="FullInstitute" type="checkbox" class="typeCheckbox" value="1" <cfif rs_typeEntity.spec_deps eq "ALL">checked="checked"</cfif> /> 全部
								
								<div id="notFullInstitute" class="secondRow <cfif rs_typeEntity.spec_deps eq "ALL">hidden_elem</cfif> mtm">
									任课学院
									<table>
										<tr>
											<cfset row = 0 />
											<cfset cellPerRow = 6 />
                                            <cfloop query="rs_institute">
												<cfset row++ />
													<td>
														<input name="targetInstitute" type="checkbox" class="typeCheckbox" <cfif row eq 1>verification="group"</cfif> value="<cfoutput>#rs_institute.institute_id#</cfoutput>" <cfif rs_typeEntity.spec_deps eq "ALL" or listFind( rs_typeEntity.spec_deps, rs_institute.institute_id, ",") >checked="checked"</cfif> />
														<cfoutput>#rs_institute.institute_short#</cfoutput>
													</td>
												<cfif row mod cellPerRow eq 0>
										</tr>
										<tr>
												</cfif>
											</cfloop>
											<cfif row eq rs_institute.recordCount and rs_institute.recordCount mod cellPerRow>
												<cfloop from="1" to="#cellPerRow-rs_institute.recordCount mod cellPerRow#" index="i">
													<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
												</cfloop>
											</cfif>
										</tr>
									</table>
								
									教辅部门
									<table>
										<tr>
											<cfset row = 0 />
											<cfset cellPerRow = 6 />

                                            <cfloop query="rs_department">
												<cfset row++ />
													<td>
														<input name="targetInstitute" type="checkbox" class="typeCheckbox" value="<cfoutput>#rs_department.institute_id#</cfoutput>" <cfif rs_typeEntity.spec_deps eq "ALL" or listFind( rs_typeEntity.spec_deps, rs_department.institute_id, ",") >checked="checked"</cfif> />
														<cfoutput>#rs_department.institute_short#</cfoutput>
													</td>
												<cfif row mod cellPerRow eq 0>
										</tr>
										<tr>
												</cfif>
											</cfloop>
											<cfif row eq rs_department.recordCount and rs_department.recordCount mod cellPerRow>
												<cfloop from="1" to="#cellPerRow-rs_department.recordCount mod cellPerRow#" index="i">
													<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
												</cfloop>
											</cfif>
										</tr>
									</table>
								</div>

							</div>
							
							<div class="lable">
								<input class="button" type="submit" value="更新" />
								<a class="button2" href="<cfoutput>#buildURL('classroomTypeRemoveDo', passArgs)#</cfoutput>">删除</a>
							</div>
							
						</form>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$(document).ready(function() {
								
								$("#FullInstitute").change(function(){
								
									var checked = $(this).prop("checked");
									
									if ( checked ) {
										$("#notFullInstitute").addClass("hidden_elem");
										$("#notFullInstitute :checkbox[name='targetInstitute']").attr("checked","checked");
									}
									else {
										$("#notFullInstitute").removeClass("hidden_elem");
										$("#notFullInstitute :checkbox[name='targetInstitute']").removeAttr("checked");
									}
								});

							});
							// -->
							//]]>
						</script>
						
					</div>
					
				</cfif>

			</div>
		</li>
	</ul>
</div>